package org.example.domain.strategy.service.rule.tree.factory;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.example.domain.strategy.model.vo.RuleLogicCheckTypeVO;
import org.example.domain.strategy.model.vo.RuleTreeVO;
import org.example.domain.strategy.service.rule.tree.ILogicTreeNode;
import org.example.domain.strategy.service.rule.tree.factory.engine.IDecisionTreeEngine;
import org.example.domain.strategy.service.rule.tree.factory.engine.impl.DecisionTreeEngine;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 规则树工厂
 */
@Service
public class DefaultTreeFactory {
//    @Resource//可去除
    private final Map<String,ILogicTreeNode> logicTreeNodeGroup;

    //当你在 DefaultTreeFactory 类的构造函数中注入 Map<String, ILogicTreeNode> 类型的 logicTreeNodeGroup 时，
    // Spring 会自动将所有实现了 ILogicTreeNode 接口的 Bean 收集到这个 Map 中。Map 的键是 Bean 的名称，值是对应的 Bean 实例。
    public DefaultTreeFactory(Map<String, ILogicTreeNode> logicTreeNodeGroup) {
        this.logicTreeNodeGroup = logicTreeNodeGroup;//构造函数注入
    }

    public IDecisionTreeEngine openLogicTree(RuleTreeVO ruleTreeVO){
        return new DecisionTreeEngine(logicTreeNodeGroup,ruleTreeVO);
    }
    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    public static  class TreeActionEntity{
            private RuleLogicCheckTypeVO ruleLogicCheckType;
            private StrategyAwardVO strategyAwardVO;
    }

    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    public static class StrategyAwardVO{
        private Integer awardId;
        private String awardRuleValue;

    }

}
